package com.scommunity.admin.controller;

import com.github.pagehelper.PageInfo;
import com.scommunity.common.ResponseResult;
import com.scommunity.domain.Feedback;
import com.scommunity.domain.User;
import com.scommunity.service.IFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/feedback")
public class FeedbackController{
    @Autowired
    IFeedbackService feedbackService;
    //写一个根据事件类型查看的方法
    // 1维修处理 2投诉 3 建议
    //事件状态类型 1 已申报 2 受理中 3 已完成
 /*   @InitBinder
    protected void initDateFormatBinder(WebDataBinder binder){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
    }*/

    @RequestMapping("/findFb")
    public ResponseResult findFB(@RequestBody Feedback feedback, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        PageInfo<Feedback> list = feedbackService.findByConditon(feedback, pageNum, pageSize);
        return ResponseResult.success(list);
    }
    @RequestMapping("/getAllRepair")
    public ResponseResult findAllRepair(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Feedback feedback = new Feedback();
        //设置1对应维修
        feedback.setFbType("维修");
        PageInfo<Feedback> list = feedbackService.findByConditon(feedback, pageNum, pageSize);
        return ResponseResult.success(list);
    }
    @RequestMapping("/getAllComplaint")
    public ResponseResult findAllComplaint(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Feedback feedback = new Feedback();
        //设置1对应维修
        feedback.setFbType("投诉");
        PageInfo<Feedback> list = feedbackService.findByConditon(feedback, pageNum, pageSize);
        //System.out.println(list);
        return ResponseResult.success(list);
    }
    @RequestMapping("/getAllSuggest")
    public ResponseResult findAllSuggest(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        Feedback feedback = new Feedback();
        //设置1对应维修
        feedback.setFbType("建议");
        PageInfo<Feedback> list = feedbackService.findByConditon(feedback, pageNum, pageSize);
       // System.out.println(list);
        return ResponseResult.success(list);
    }

    @RequestMapping("/updateFb")
    public ResponseResult updateFB(@RequestBody Feedback feedback){
        //System.out.println(feedback);
        //feedbackService.update(feedback,new UpdateWrapper<Feedback>().eq("fb_id",feedback.getFbId()));
        feedbackService.updateById(feedback);
        return ResponseResult.success();
    }
    @RequestMapping("/findAll")
    public ResponseResult findAll(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageInfo<Feedback> pages = feedbackService.getFeedbackByPage(pageNum, pageSize);
        return ResponseResult.success(pages);
    }
    //新增反馈
    @RequestMapping("/addFb")
    public ResponseResult addFb(@SessionAttribute User user, @RequestBody Feedback feedback){
        boolean save = feedbackService.save(feedback);
        if (save){
            return ResponseResult.success();
        }
        return ResponseResult.error(401,"反馈失败");
    }
    @RequestMapping("/delete")
    public ResponseResult delete(@RequestParam Long feedbackId){
        boolean b = feedbackService.removeById(feedbackId);
        if (b){
            return ResponseResult.success();
        }
        return ResponseResult.error(401,"反馈删除失败");
    }

}
